ioemu: cope with partial reads/writes when using the read()/write()
authorKeir Fraser <keir.fraser@citrix.com>
Mon, 11 Feb 2008 14:47:06 +0000 (14:47 +0000)
committerKeir Fraser <keir.fraser@citrix.com>
Mon, 11 Feb 2008 14:47:06 +0000 (14:47 +0000)
syscall interfaces.
Signed-off-by: Samuel Thibault <samuel.thibault@eu.citrix.com>
tools/ioemu/block-raw.c

index 1ecf29cdb54ee17d41cfebc1c3903765c2e7654d..182d2ec55e07457361f1192e2cd835cbab751f68 100644 (file)
@@ -169,10 +169,16 @@ static int raw_pread(BlockDriverState *bs, int64_t offset,
     }
     s->lseek_err_cnt=0;
 
-    ret = read(s->fd, buf, count);
-    if (ret == count) 
-        goto label__raw_read__success;
+    uint64_t done;
+    for (done = 0; done < count; done += ret) {
+       ret = read(s->fd, buf + done, count - done);
+       if (ret == -1) 
+           goto label__raw_read__error;
+    }
+    ret = count;
+    goto label__raw_read__success;
     
+label__raw_read__error:
     DEBUG_BLOCK_PRINT("raw_read(%d:%s, %" PRId64 ", %p, %d) [%" PRId64 "] read failed %d : %d = %s\n", 
         s->fd, 
         bs->filename, 
@@ -234,9 +240,16 @@ static int raw_pwrite(BlockDriverState *bs, int64_t offset,
     }
     s->lseek_err_cnt = 0;
 
-    ret = write(s->fd, buf, count);
-    if (ret == count) 
-        goto label__raw_write__success;
+    uint64_t done;
+    for (done = 0; done < count; done += ret) {
+       ret = write(s->fd, buf + done, count - done);
+       if (ret == -1) 
+           goto label__raw_write__error;
+    }
+    ret = count;
+    goto label__raw_write__success;
+
+label__raw_write__error:
     
     DEBUG_BLOCK_PRINT("raw_write(%d:%s, %" PRId64 ", %p, %d) [%" PRId64 "] write failed %d : %d = %s\n", 
         s->fd,